package com.jmu.edu.IMApplication.adapter;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

import java.util.List;

public class MainPageViewAdapter extends FragmentPagerAdapter {

    private List<Fragment> fragmentList;

    /**
     * @param fm            传入的FragmentManager
     * @param fragmentList 传入的Fragment列表
     */
    public MainPageViewAdapter(@NonNull FragmentManager fm, List<Fragment> fragmentList) {
        super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
        this.fragmentList = fragmentList;
    }

    /**
     *
     * @param position 传入的Fragment的下标
     * @return 根据position返回对应的Fragment
     */
    @Override
    public Fragment getItem(int position) {
        return fragmentList.get(position);
    }

    @Override
    public int getCount() {
        return fragmentList.size();
    }

}
